// pages/me_content/orders.js
import { getOrderList } from '../api/index';

Page({
  data: {
    formData:{
    },
    tabList: [
      { name: '全部', value: 0 },
      { name: '待支付', value: 1 },
      { name: '待接单', value: 2 },
      { name: '进行中', value: 3 },
      { name: '已完成', value: 4 },
    ],
    active: 0,
    orderList: null,
    total: 0,
    type: '',
    statusMap: {
      0: '',
      1: '待支付',
      2: '待接单',
      3: '进行中',
      4: '发单员确认完成'
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options, 'options');
    if(options.type){
      const jdyTabs = [
        { name: '全部', value: 0 },
        { name: '进行中', value: 3 },
        { name: '已完成', value: 4 }
      ];
      
      this.setData({ 
        type: options.type,
        tabList: options.type === 'jdy' ? jdyTabs : this.data.tabList,
        active: options.type === 'jdy' ? 0 : 0
      });

    }
    // this.getOrderList();
  },
  onShow() {
    this.getOrderList();
  },
  onChange(event) {
    const active = event.detail.name;
    this.setData({ active });
    this.getOrderList();
  },
  getOrderList() {
    getOrderList({
      ...this.data.formData,
      status: this.data.statusMap[this.data.active],
      receiver: this.data.type === 'jdy' ? wx.getStorageSync('openId') : '',
    }).then(res => {
     
      this.setData({ 
        orderList: res.result,
      });
    })
  }
})